package com.irdstudio.apicenter.frame.core.jdbc;

//package com.yuchengtech.maccs.core.jdbc;
//
//import java.lang.reflect.InvocationTargetException;
//import java.sql.Connection;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//import org.apache.commons.beanutils.BeanUtils;
//import org.apache.commons.dbutils.BeanProcessor;
//import org.apache.commons.dbutils.QueryRunner;
//import org.apache.commons.dbutils.handlers.BeanHandler;
//import org.apache.commons.dbutils.handlers.BeanListHandler;
//import org.apache.commons.dbutils.handlers.MapListHandler;
//import org.apache.commons.dbutils.handlers.ScalarHandler;
//import org.apache.commons.lang.StringUtils;
//
//import com.yuchengtech.maccs.core.dm.AppBaseInfo;
//import com.yuchengtech.maccs.core.dm.MaccsBean;
//
//
///**
// * 移动服务端数据库工具类（JDBC）
// * 
// * 
// * <p>
// * 提供面向对象的增删改查 , 同时提供SQL语句操作
// * <p>
// * 对于相面对象的标准操作,使用移动应用端统一bean接口对象{@link DataBean}
// * <p>
// * 即：对于需要进行数据库交互封装的bean 必须是一个 MaccsBean对象
// * 
// * @see DataBean
// * 
// * @author ZhangHao
// * @version 1.0
// * @date 2015-06-04
// *
// */
//@Deprecated
//public class MaccsDBUtils {
//
////	/**
////	 * 新增一个bean 对象
////	 * 
////	 * @param conn
////	 * @param obj
////	 * @return
////	 */
////	public static int insert(Connection conn, DataBean bean) {
////		if (bean == null) {
////			throw new JdbcDBException("bean is null.");
////		}
////
////		String sql;
////		List<String> paramsList;
////		try {
////			sql = SQLUtil.getInsertSQL(bean);
////			paramsList = SQLUtil.getParams(bean);
////		} catch (Exception e) {
////			throw new JdbcDBException("insert error!", e);
////		}
////
////		return insert(conn, sql, paramsList.toArray());
////	}
////
////	/**
////	 * 执行新增的SQL语句
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param params
////	 * @return
////	 */
////	public static int insert(Connection conn, String sql, Object... params) {
////		try {
////			return new QueryRunner().update(conn, sql, params);
////		} catch (SQLException e) {
////			e.printStackTrace();
////			throw new JdbcDBException("insert error!", e);
////		}
////	}
////
////	/**
////	 * 删除一个 bean 对象
////	 * 
////	 * @param conn
////	 * @param obj
////	 * @param keyPropName
////	 * @return
////	 */
////	public static int delete(Connection conn, DataBean bean, String keyPropName) {
////
////		if (bean == null)
////			throw new JdbcDBException("obj is null.");
////
////		if (StringUtils.isBlank(keyPropName))
////			throw new JdbcDBException("keyPropName is null.");
////		String sql;
////		Object[] params;
////		try {
////			sql = SQLUtil.getDeleteSQL(bean, keyPropName);
////			params = new Object[] { BeanUtils.getProperty(bean, keyPropName) };
////		} catch (Exception e) {
////			throw new JdbcDBException("delete error!", e);
////		}
////
////		return delete(conn, sql, params);
////	}
////
////	/**
////	 * 执行删除的SQL语句
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param params
////	 * @return
////	 */
////	public static int delete(Connection conn, String sql, Object... params) {
////		try {
////			return new QueryRunner().update(conn, sql, params);
////		} catch (SQLException e) {
////			e.printStackTrace();
////			throw new JdbcDBException("delete error!", e);
////		}
////	}
////
////	/**
////	 * 修改一个bean对象
////	 * 
////	 * @param conn
////	 * @param obj
////	 * @param keyPropName
////	 * @return
////	 */
////	public static int update(Connection conn, DataBean bean, String keyPropName) {
////		if (bean == null)
////			throw new JdbcDBException("obj is null.");
////
////		if (StringUtils.isBlank(keyPropName))
////			throw new JdbcDBException("keyPropName is null.");
////		String sql;
////		Object[] params;
////		try {
////			sql = SQLUtil.getDeleteSQL(bean, keyPropName);
////			params = new Object[] { BeanUtils.getProperty(bean, keyPropName) };
////		} catch (Exception e) {
////			throw new JdbcDBException("update error!", e);
////		}
////
////		return update(conn, sql, params);
////	}
////
////	/**
////	 * 执行修改的SQL语句
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param params
////	 * @return
////	 */
////	public static int update(Connection conn, String sql, Object... params) {
////		try {
////			return new QueryRunner().update(conn, sql, params);
////		} catch (SQLException e) {
////			e.printStackTrace();
////			throw new JdbcDBException("update error!", e);
////		}
////	}
////
////	/**
////	 * 查询一个bean 对象
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param clazz
////	 * @param collId
////	 * @return
////	 */
////	public static DataBean findObj(Connection conn, Class clazz, String keyPropName,Object idPropertyValue) {
////		try {
////			
////			String sql = SQLUtil.getSelectSQL(keyPropName, clazz.newInstance());
////			
////			return new QueryRunner().query(conn, sql, new BeanHandler<DataBean>(
////					clazz), new Object[]{idPropertyValue});
////
////		} catch (Exception e) {
////			e.printStackTrace();
////			throw new JdbcDBException("find error!", e);
////		}
////	}
////
////	/**
////	 * 查询一个bean 集合
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param clazz
////	 * @param params
////	 * @return
////	 */
////	@SuppressWarnings({ "unchecked", "rawtypes" })
////	public static List<? extends DataBean> findList(Connection conn,
////			String sql, Class clazz, Object... params) {
//////		try {
////////			 List<? extends DataBean> rsList = (List<? extends DataBean>)new QueryRunner().query(conn,
////////					sql, new BeanListHandler(clazz, new BeanProcessor(columnToPropertyOverrides)), params);
//////			 
////////			 return null;
//////		} catch (SQLException e) {
//////			e.printStackTrace();
//////			throw new JdbcDBException("findList error!", e);
//////		}
////		return null;
////	}
////
////	/**
////	 * 查询一个MAP集合
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param clazz
////	 * @param params
////	 * @return
////	 */
////	public static List<Map<String, Object>> findMapList(Connection conn,
////			String sql, Class<Object> clazz, Object... params) {
////		try {
////
////			return new QueryRunner().query(conn, sql, new MapListHandler(),
////					params);
////
////		} catch (SQLException e) {
////			e.printStackTrace();
////			throw new JdbcDBException("findMapList error!", e);
////		}
////	}
////
////	/**
////	 * 查询单个值
////	 * 
////	 * @param conn
////	 * @param sql
////	 * @param params
////	 * @return
////	 */
////	public static Object findSingleValue(Connection conn, String sql,
////			Object... params) {
////		try {
////			return new QueryRunner().query(conn, sql,
////					new ScalarHandler<Object>(1), params);
////		} catch (SQLException e) {
////			e.printStackTrace();
////			throw new JdbcDBException("findSingleValue error!", e);
////		}
////	}
////
////	/**
////	 * 
////	 * SQL 工具 包括SQL语句的拼装等方法
////	 * 
////	 * 
////	 * @author ZhangHao
////	 * @version 1.0
////	 * @date 2015-06-04
////	 *
////	 */
////
////	static class SQLUtil {
////
////		/**
////		 * 根据属性名称获取数据库字段名
////		 * 
////		 * @param prop
////		 * @return
////		 */
////		public static String getTrueFieldName(String prop) {
////			StringBuilder columnName = new StringBuilder();
////			for (int i = 0; i < prop.length(); i++) {
////				if (Character.isUpperCase(prop.charAt(i))) {
////					if (i > 0) {
////						columnName.append("_");
////					}
////				}
////				columnName.append(prop.charAt(i));
////			}
////			return columnName.toString();
////		}
////
////		/**
////		 * 根据bean获取数据库表名
////		 * 
////		 * @param tableClass
////		 * @return
////		 */
////		public static String getTrueTableName(Object bean) {
////			String name = bean.getClass().getSimpleName();
////			name = (new StringBuilder(String.valueOf(Character.toLowerCase(name
////					.charAt(0)))).append(name.substring(1))).toString();
////			return getTrueFieldName(name);
////		}
////
////		/**
////		 * 根据bean获取新增SQL语句
////		 * 
////		 * @param obj
////		 * @return
////		 * @throws Exception
////		 * @throws InvocationTargetException
////		 * @throws IllegalAccessException
////		 */
////		@SuppressWarnings("unchecked")
////		public static String getInsertSQL(Object obj) throws Exception {
////			String tableName = SQLUtil.getTrueTableName(obj);
////			StringBuilder sql = new StringBuilder();
////			StringBuilder body1 = new StringBuilder();
////			StringBuilder body2 = new StringBuilder();
////			sql.append("insert into  ").append(tableName).append("(");
////			Map<String, Object> map = BeanUtils.describe(obj);
////			for (String prop : map.keySet()) {
////				if (prop.equals("class")) {
////					continue;
////				}
////				body1.append(SQLUtil.getTrueFieldName(prop)).append(",");
////				body2.append("?,");
////			}
////			body1.deleteCharAt(body1.length() - 1);
////			body2.deleteCharAt(body2.length() - 1);
////			sql.append(body1).append(") values (").append(body2).append(")");
////
////			return sql.toString();
////		}
////
////		/**
////		 * 
////		 * 根据bean 获取删除SQL语句
////		 * 
////		 * @param conn
////		 * @param obj
////		 * @param keyPropName
////		 * @return
////		 */
////		public static String getDeleteSQL(Object obj, String keyPropName) {
////			String tableName = SQLUtil.getTrueTableName(obj);
////			StringBuilder sql = new StringBuilder();
////			sql.append("delete from ").append(tableName).append(" where ");
////			sql.append(SQLUtil.getTrueFieldName(keyPropName)).append("=?");
////
////			return sql.toString();
////
////		}
////
////		/**
////		 * 获取bean 对象的更新语句
////		 * 
////		 * @param conn
////		 * @param obj
////		 * @param keyPropName
////		 * @return
////		 * @throws Exception
////		 */
////		@SuppressWarnings("unchecked")
////		public static String getUpdateSQL(Object obj, String keyPropName)
////				throws Exception {
////
////			String tableName = getTrueTableName(obj);
////			StringBuilder sql = new StringBuilder();
////			sql.append("update ").append(tableName).append(" SET ");
////			Map<String, Object> map;
////			map = BeanUtils.describe(obj);
////			for (String prop : map.keySet()) {
////				if (keyPropName.equals(prop)) {
////					continue;
////				}
////				if (prop.equals("class")) {
////					continue;
////				}
////				sql.append(getTrueFieldName(prop)).append("=?").append(",");
////			}
////			sql.deleteCharAt(sql.length() - 1);
////			sql.append(" where ");
////			sql.append(getTrueFieldName(keyPropName)).append("=?");
////
////			return sql.toString();
////
////		}
////
////		
////		/**
////		 * 获取bean对象的查询语句
////		 * @param keyPropName
////		 * @param obj
////		 * @return
////		 */
////		public static String getSelectSQL(String keyPropName, Object obj) {
////
////			StringBuilder sql = new StringBuilder();
////
////			sql.append(" select * from   ").append(getTrueTableName(obj))
////					.append(" where ");
////
////			sql.append(getTrueFieldName(keyPropName)).append("=?");
////
////			return sql.toString();
////		}
////
////		/**
////		 * 获取bean 对象的属性值
////		 * 
////		 * @param obj
////		 * @return
////		 * @throws Exception
////		 */
////		@SuppressWarnings("unchecked")
////		public static List<String> getParams(Object obj) throws Exception {
////			Map<String, Object> map = BeanUtils.describe(obj);
////			List<String> paramList = new ArrayList<String>(map.size());
////			for (String prop : map.keySet()) {
////				if (prop.equals("class")) {
////					continue;
////				}
////				paramList.add(BeanUtils.getProperty(obj, prop));
////			}
////			return paramList;
////		}
////	}
////	
////	
////	public static void main(String[] args) {
////		ConnectionManager m = com.yuchengtech.maccs.util.spring.BeanUtils.getBean(ConnectionManager.class);
////		AppBaseInfo in  = (AppBaseInfo) MaccsDBUtils.findObj(m.getConnection(), AppBaseInfo.class, "appId", "0001");
////		
////		
////	}
//
// }
